package com.glut.campusrepair.controller;

import com.glut.campusrepair.entity.FailureRepair;
import com.glut.campusrepair.service.IFailureRepairPostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  前端控制器
 *
 * @author stubborn
 * @since 2024-07-20 15:08
 */
@CrossOrigin
@RestController
@Slf4j
public class FailureRepairPostController {

    @Autowired
    IFailureRepairPostService failureRepairPoseService;

    @PostMapping("/failure-repair/save")  //前端：axios.post()
    public boolean save(@RequestBody FailureRepair failureRepair) { //@RequestBody将请求的JSON数据解析成POJO对象

        return failureRepairPoseService.save(failureRepair);

    }

    @GetMapping("/failure-repair/selectAll")
    public List<FailureRepair> selectAll() {
        return failureRepairPoseService.selectAll();
    }

    @GetMapping("/failure-repair/select/{userNo}")
    public List<FailureRepair> selectByUserNo(@PathVariable String userNo) {
        return failureRepairPoseService.selectByUserNo(userNo);

    }

    @PutMapping("/failure-repair/update")
    public boolean updateFailureRepair(@RequestBody FailureRepair failureRepair) {
        return failureRepairPoseService.updateFailureRepair(failureRepair);
    }

    @DeleteMapping("/failure-repair/delete/{id}")
    public boolean deleteFailureRepair(@PathVariable Integer id) {
        return failureRepairPoseService.deleteFailureRepair(id);
    }

}
